home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Snippets / Development Tools & Languages / Eenie / UEenie.cp < prev    next >
Encoding:
Text File  |  1992-07-15  |  10.6 KB  |  442 lines  |  [TEXT/MPS ]

  1. // UEenie.cp --------------------------------------------------------------------------
  2. // Copyright © 1991 by Apple Computer, Inc. All rights reserved.
  3.  
  4. #pragma once
  5.  
  6. // INCLUDES ---------------------------------------------------------------------------
  7.  
  8. #include "EenieRez.h"                                        // combined header file for resource IDs
  9. #include "UEenie.h"                                            // class definitions
  10.  
  11.  
  12. // CLASS METHODS ----------------------------------------------------------------------
  13.  
  14. // TAdornerApplication ----------------------------------------------------------------
  15.  
  16. #pragma segment AInit
  17. pascal void TAdornerApplication::IAdornerApplication(OSType fileType, OSType creator)
  18. {
  19.     inherited::IApplication(fileType, creator);
  20.  
  21.     if (gDeadStripSuppression){                                // so the linker doesn't dead strip class info 
  22.         macroDontDeadStrip(TEenieView1);
  23.         macroDontDeadStrip(TEenieView2);
  24.         macroDontDeadStrip(TEenieView3);
  25.         macroDontDeadStrip(TEenieView4);
  26.         macroDontDeadStrip(TGrayFill);
  27.         macroDontDeadStrip(TOtherGrayFill);
  28.         macroDontDeadStrip(TEtchedFrame);
  29.     }
  30.         RegisterStdType("TGrayFill", 'gray');                // register adorner types
  31.         RegisterStdType("TOtherGrayFill", 'dgry');                
  32.         RegisterStdType("TEtchedFrame", 'etch');
  33. }
  34.  
  35.  
  36. #pragma segment AOpen
  37. pascal TDocument* TAdornerApplication::DoMakeDocument(CommandNumber /* itsCmdNumber */,
  38.                                                       TFile*    /* itsFile */)
  39. {
  40.     FailInfo fi;
  41.     
  42.     if(fi.Try()){
  43.         TAdornerDocument* aAdornerDocument = new TAdornerDocument;
  44.         aAdornerDocument->IAdornerDocument();
  45.         return aAdornerDocument;
  46.         fi.Success();
  47.     }
  48.     else
  49.         fi.ReSignal();
  50. }
  51.  
  52.  
  53. // TAdornerDocument Methods -----------------------------------------------------------
  54.  
  55. #pragma segment AInit
  56. pascal void TAdornerDocument::IAdornerDocument()
  57. {
  58.     inherited::IDocument();
  59. }
  60.  
  61.  
  62. #pragma segment AOpen
  63. pascal void TAdornerDocument::DoMakeViews(Boolean /*forPrinting*/)
  64. {
  65.     TWindow*        aWindow        = NULL;
  66.     TEenieView1*    view1        = NULL;
  67.     TEenieView2*    view2        = NULL;
  68.     TEenieView3*    view3        = NULL;
  69.     TEenieView4*    view4        = NULL;
  70.  
  71.     FailInfo fi;
  72.     
  73.     if(fi.Try()){
  74.         // create Window    
  75.         aWindow = (TWindow *)gViewServer->NewTemplateWindow(kDefaultWindowID, this);
  76.     
  77.         // add window adorner
  78.         aWindow->AddAdorner(NewStdAdorner('dgry',"",'dgry', kFreeOnDeletion), 
  79.                                             kAdornLast, kRedraw);
  80.     
  81.         // create views
  82.         view1   =(TEenieView1 *) aWindow->FindSubView('VW01'); FailNIL(view1);
  83.         view2   =(TEenieView2 *) aWindow->FindSubView('VW02'); FailNIL(view2);
  84.         view3   =(TEenieView3 *) aWindow->FindSubView('VW03'); FailNIL(view3);
  85.         view4   =(TEenieView4 *) aWindow->FindSubView('VW04'); FailNIL(view4);
  86.  
  87.         // add adorners to the new views
  88.         view1->AddAdorner(NewStdAdorner('gray',"",'gray', kFreeOnDeletion), 
  89.                             kAdornFirst, kRedraw);
  90.         view2->AddAdorner(NewStdAdorner('gray',"",'gray', kFreeOnDeletion), 
  91.                             kAdornFirst, kRedraw);
  92.         view3->AddAdorner(NewStdAdorner('gray',"",'gray', kFreeOnDeletion), 
  93.                             kAdornFirst, kRedraw);
  94.         view4->AddAdorner(NewStdAdorner('gray',"",'gray', kFreeOnDeletion), 
  95.                             kAdornFirst, kRedraw);
  96.         
  97.         // create dependencies
  98.         view1->AddDependent(view4); view2->AddDependent(view3);
  99.         view3->AddDependent(view2); view4->AddDependent(view1);
  100.  
  101.         fi.Success();
  102.     }
  103.     else
  104.         fi.ReSignal();
  105. }
  106.  
  107.  
  108. // TEenieView ----------------------------------------------------------------
  109.  
  110. #pragma segment AInit
  111. pascal void TEenieView::Initialize()
  112. {
  113.     inherited::Initialize();
  114. }
  115.  
  116.  
  117. #pragma segment ARes
  118. pascal void TEenieView::DoPostCreate(TDocument* itsDocument)
  119. {
  120.     inherited::DoPostCreate(itsDocument);
  121.     this->fCounter = 0L;                // zero counter
  122.     this->AddAdorner(NewStdAdorner('etch',"",'etch', kFreeOnDeletion), 
  123.                                     kAdornFirst, kRedraw);
  124. }
  125.  
  126.  
  127. #pragma segment Main
  128. pascal void TEenieView::Hilite()
  129. {
  130.     Rect tempRect;
  131.  
  132.     this->GetQDExtent(tempRect);        // get the area
  133.     BitClr((Ptr)HiliteMode, 0);            // clear bit for selection color
  134.     HiliteColor(gDKPink);                // switch temp to new hilite color
  135.     InvertRect(tempRect);                // invert the area
  136. }
  137.  
  138.  
  139. // TEenieView SubViews ----------------------------------------------------------
  140.  
  141. #pragma segment ARes
  142. pascal void TEenieView1::Draw(const VRect& area)
  143. {    
  144.     inherited::Draw(area);
  145.     this->DrawNumber();    
  146. }
  147.  
  148.  
  149. #pragma segment ARes
  150. pascal void TEenieView1::DrawNumber()
  151. {
  152.     Str255 first = "Moo view clicked";
  153.     Str255 count;
  154.     Str255 second = "times...";
  155.     
  156.     PenNormal();
  157.     
  158.     TextFont(times); TextSize(14); MoveTo(10,15);
  159.     DrawString(first);
  160.  
  161.     TextSize(48); MoveTo(40,90);
  162.     NumToString(this->fCounter, count);
  163.     DrawString(count);
  164.     
  165.     TextSize(14); MoveTo(10,140);
  166.     DrawString(second);
  167. }
  168.  
  169. #pragma segment Main
  170. pascal void    TEenieView1::DoMouseCommand(VPoint&         /*theMouse*/,
  171.                                           TToolboxEvent*     /*event*/,
  172.                                           Point             /*hysteresis*/)
  173. {
  174.     this->Hilite();                    // flash for the user for mouse click
  175.     this->Changed(eVIEW1,this);        // send change directive to dependent view
  176. }
  177.  
  178. #pragma segment ARes
  179. pascal void TEenieView1::DoUpdate(    ChangeID theID,
  180.                                     TObject* /*changedObject*/,
  181.                                     TObject* /*changedBy*/)
  182. {
  183.     if (theID == eVIEW4){
  184.         this->fCounter = this->fCounter + 1L;                // increment counter
  185.         this->ForceRedraw();                                // update the screen
  186.     }
  187. }
  188.  
  189.  
  190. // --------------------------
  191.  
  192. #pragma segment ARes
  193. pascal void TEenieView2::Draw(const VRect& area)
  194. {    
  195.     inherited::Draw(area);
  196.     this->DrawNumber();    
  197. }
  198.  
  199.  
  200. #pragma segment ARes
  201. pascal void TEenieView2::DrawNumber()
  202. {
  203.     Str255 first = "Minee view clicked";
  204.     Str255 count;
  205.     Str255 second = "times...";
  206.     
  207.     PenNormal();
  208.     
  209.     TextFont(times); TextSize(14); MoveTo(10,15);
  210.     DrawString(first);
  211.  
  212.     TextSize(48); MoveTo(40,90);
  213.     NumToString(this->fCounter, count);
  214.     DrawString(count);
  215.     
  216.     TextSize(14); MoveTo(10,140);
  217.     DrawString(second);
  218. }
  219.  
  220.  
  221. #pragma segment Main
  222. pascal void    TEenieView2::DoMouseCommand(VPoint&         /*theMouse*/,
  223.                                           TToolboxEvent*  /*event*/,
  224.                                           Point             /*hysteresis*/)
  225. {
  226.     this->Hilite();                    // flash for the user for mouse click
  227.     this->Changed(eVIEW2,this);        // send change directive to dependent view
  228. }
  229.  
  230.  
  231. #pragma segment ARes
  232. pascal void TEenieView2::DoUpdate(    ChangeID theID,
  233.                                     TObject* /*changedObject*/,
  234.                                     TObject* /*changedBy*/)
  235. {
  236.     if (theID == eVIEW3) {
  237.     this->fCounter = this->fCounter + 1L;                        // increment counter
  238.     this->ForceRedraw();                                        // update the screen
  239.     }
  240. }
  241.  
  242.  
  243. // --------------------------
  244.  
  245. #pragma segment ARes
  246. pascal void TEenieView3::Draw(const VRect& area)
  247. {    
  248.     inherited::Draw(area);
  249.     this->DrawNumber();
  250. }
  251.  
  252.  
  253. #pragma segment ARes
  254. pascal void TEenieView3::DrawNumber()
  255. {
  256.     Str255 first = "Meenie view clicked";
  257.     Str255 count;
  258.     Str255 second = "times...";
  259.     
  260.     PenNormal();
  261.     
  262.     TextFont(times); TextSize(14); MoveTo(10,15);
  263.     DrawString(first);
  264.  
  265.     TextSize(48); MoveTo(40,90);
  266.     NumToString(this->fCounter, count);
  267.     DrawString(count);
  268.     
  269.     TextSize(14); MoveTo(10,140);
  270.     DrawString(second);
  271. }
  272.  
  273.  
  274. #pragma segment Main
  275. pascal void    TEenieView3::DoMouseCommand(VPoint&         /*theMouse*/,
  276.                                           TToolboxEvent*     /*event*/,
  277.                                           Point             /*hysteresis*/)
  278. {
  279.     this->Hilite();                    // flash for the user for mouse click
  280.     this->Changed(eVIEW3,this);        // send change directive to dependent view
  281. }
  282.  
  283.  
  284. #pragma segment ARes
  285. pascal void TEenieView3::DoUpdate(    ChangeID   theID,
  286.                                     TObject*   /*changedObject*/,
  287.                                     TObject*   /*changedBy*/)
  288. {
  289.     if (theID == eVIEW2) { 
  290.     this->fCounter = this->fCounter + 1L;                // increment counter
  291.     this->ForceRedraw();                                // update the screen
  292.     }
  293. }
  294.  
  295.  
  296. // --------------------------
  297.  
  298. #pragma segment ARes
  299. pascal void TEenieView4::Draw(const VRect& area)
  300. {    
  301.     inherited::Draw(area);
  302.     this->DrawNumber();
  303. }
  304.  
  305. #pragma segment ARes
  306. pascal void TEenieView4::DrawNumber()        // draw information in view
  307. {
  308.     Str255 first = "Eenie view clicked";
  309.     Str255 count;
  310.     Str255 second = "times...";
  311.     
  312.     PenNormal();
  313.     
  314.     TextFont(times); TextSize(14); MoveTo(10,15);
  315.     DrawString(first);
  316.  
  317.     TextSize(48); MoveTo(40,90);
  318.     NumToString(this->fCounter, count);
  319.     DrawString(count);
  320.     
  321.     TextSize(14); MoveTo(10,140);
  322.     DrawString(second);
  323. }
  324.  
  325.  
  326. #pragma segment Main
  327. pascal void    TEenieView4::DoMouseCommand(VPoint&         /*theMouse*/,
  328.                                           TToolboxEvent*     /*event*/,
  329.                                           Point             /*hysteresis*/)
  330. {
  331.     this->Hilite();                    // flash for the user for mouse click
  332.     this->Changed(eVIEW4,this);        // send change directive to dependent view
  333. }
  334.  
  335. #pragma segment ARes
  336. pascal void TEenieView4::DoUpdate(    ChangeID theID,
  337.                                     TObject* /*changedObject*/,
  338.                                     TObject* /*changedBy*/)
  339. {
  340.     if (theID == eVIEW1){
  341.         this->fCounter = this->fCounter + 1L;        // increment counter
  342.         this->ForceRedraw();                        // update the screen
  343.     }
  344. }
  345.  
  346.  
  347. // TAdorners ------------------------------------------------------------------
  348.  
  349. #pragma segment ARes
  350. pascal void TGrayFill::Draw(TView* itsView, const VRect& /*area*/)
  351. {
  352.     RGBColor    saveColor;
  353.     PenState    savePenState;
  354.     VRect        adornArea;
  355.     Rect        QDArea;
  356.     Rect        tempRect;
  357.  
  358.     GetPenState(savePenState);            // save off the current pen state 
  359.     GetIfColor(saveColor);                // and the foreground color
  360.     PenNormal();
  361.  
  362.     itsView->GetAdornExtent(adornArea);    // get area
  363.     itsView->ViewToQDRect(adornArea, QDArea);
  364.     tempRect = QDArea;
  365.  
  366.     SetIfColor(gRGBGray);                // colorize it
  367.     PaintRect(tempRect);
  368.  
  369.     SetIfColor(saveColor);                // restore the foreground color and the pen
  370.     SetPenState(savePenState);
  371. }
  372.  
  373.  
  374. #pragma segment ARes
  375. pascal void TOtherGrayFill::Draw(TView* itsView, const VRect& /*area*/)
  376. {
  377.     RGBColor    saveColor;
  378.     PenState    savePenState;
  379.     VRect        adornArea;
  380.     Rect        QDArea;
  381.     Rect        tempRect;
  382.  
  383.     GetPenState(savePenState);            // save off the current pen state 
  384.     GetIfColor(saveColor);                // and the foreground color
  385.     PenNormal();
  386.  
  387.     itsView->GetAdornExtent(adornArea);    // get area 
  388.     itsView->ViewToQDRect(adornArea, QDArea);
  389.     tempRect = QDArea;
  390.  
  391.     SetIfColor(gDKGray);                // dark gray scale, grey for you English
  392.     PaintRect(tempRect);
  393.  
  394.     SetIfColor(saveColor);                // Restore the foreground color and the pen
  395.     SetPenState(savePenState);
  396. }
  397.  
  398.  
  399. #pragma segment ARes
  400. pascal void TEtchedFrame::Initialize()    
  401. {
  402.     inherited::Initialize();
  403.     fInset.h = 1;
  404.     fInset.v = 1;
  405. }
  406.  
  407.  
  408. #pragma segment ARes
  409. pascal void TEtchedFrame::Draw(TView* itsView, const VRect&    /*area*/)
  410. {
  411.     RGBColor    saveColor;
  412.     PenState    savePenState;
  413.     VRect         adornArea;
  414.     Rect        QDArea;
  415.     Rect        tempRect;
  416.  
  417.     GetPenState(savePenState);            //  Save off the current pen state 
  418.     GetIfColor(saveColor);                // and the foreground color
  419.     PenNormal();
  420.  
  421.     itsView->GetAdornExtent(adornArea);    // get area
  422.     itsView->ViewToQDRect(adornArea, QDArea);
  423.     tempRect = QDArea;
  424.  
  425.     SetIfColor(gRGBBlack);
  426.     InsetRect(tempRect, fInset.h, fInset.v);
  427.     FrameRect(tempRect);                                    // Frame the shadows 
  428.  
  429.     OffsetRect(tempRect, 1, 1);
  430.     SetIfColor(gRGBWhite);
  431.     FrameRect(tempRect);                                    // Frame the light edges 
  432.  
  433.     OffsetRect(tempRect, -1, -1);
  434.     SetCPixel(tempRect.left, tempRect.bottom, gRGBBlack);    // Finish the corners 
  435.     SetCPixel(tempRect.right, tempRect.top, gRGBBlack);
  436.  
  437.     SetIfColor(saveColor);                // Restore the foreground color and the pen
  438.     SetPenState(savePenState);
  439. }
  440.  
  441.  
  442.